﻿using System.Data;
using Microsoft.ApplicationBlocks.Data;
using viPage.Providers;
using visinia.SmartEngine.Providers;

namespace viPage
{
    public class SqlDataProvider : viPageDataProvider
    {
        #region INIT
        private static string _sqlConnectionString = null;

        public SqlDataProvider()
        {
            _sqlConnectionString = ProviderController.GetDataProviderConnectionString();
        }
        public string ConnectionString
        {
            get { return _sqlConnectionString; }
        }
        #endregion

        #region PAGES
        public override IDataReader GetPages()
        {
            return SqlHelper.ExecuteReader(ConnectionString, "viPageGetPages");
        }

        public override IDataReader AddPage(int WebPageId, string Name, string Title)
        {
            return SqlHelper.ExecuteReader(ConnectionString, "viPageAddPage", WebPageId, Name, Title);
        }

        public override void UpdatePage(int PageId, int WebPageId, string Name, string Title)
        {
            SqlHelper.ExecuteNonQuery(ConnectionString, "viPageUpdatePage", PageId, WebPageId, Name, Title);
        }

        public override void DeletePage(int PageId)
        {
            SqlHelper.ExecuteNonQuery(ConnectionString, "viPageDeletePage", PageId);
        }
        #endregion

        #region BASE SETTINGS
        public override void AddBaseSetting(string key, string value)
        {
            SqlHelper.ExecuteNonQuery(ConnectionString, "viPageAddBaseSetting", key, value);
        }

        public override void DeleteBaseSetting(string key)
        {
            SqlHelper.ExecuteNonQuery(ConnectionString, "viPageDeleteBaseSetting", key);
        }

        public override void UpdateBaseSetting(string key, string value)
        {
            SqlHelper.ExecuteNonQuery(ConnectionString, "viPageUpdateBaseSetting", key, value);
        }

        public override IDataReader GetBaseSettings()
        {
            return SqlHelper.ExecuteReader(ConnectionString, "viPageGetBaseSettings");
        }
        #endregion
    }
}
